<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <script type="text/javascript" src="../static/dist/layui.js"></script>
    <link rel="stylesheet" href="../static/dist/css/layui.css">
    <script type="text/javascript" src="../static/dist/tableSelect.js"></script>
    <title>TableSelect</title>
    <style>
        .layui-table-cell{
            text-align:center;

            height: auto;

            white-space: normal;

        }

        .layui-table img{
            max-width:300px
        }
    </style>
</head>


<div class="layui-row layui-bg-black" >
    <div class="layui-col-md1 layui-bg-black">
        <a href="/">
            <img src="../static/logo.png" class="layui-logo" style="height:55px">
        </a>
    </div>
   <div class="layui-col-md8 layui-bg-black">
        <form class="layui-form" action="" style="padding:11px">
            <div class="layui-form-item" style="height: 18px">
                <div class="layui-input-inline" style="width:850px">
                    <input type="text" name="" placeholder="请输入" autocomplete="off" class="layui-input" id="search">
                </div>
                <button type="button" class="layui-btn layui-btn-primary layui-btn-warm" id="searchBtn">
                    <i class="layui-icon layui-icon-search"></i>
                </button>
            </div>
        </form>
    </div>
    <div class="layui-col-md3 layui-bg-black" >
        <ul class="layui-nav" style="padding:0px;bottom: 3px">
            {% if user %}
                <li class="layui-nav-item">
                    <a href="/user/manage"><img src="../static/yang.jpeg" class="layui-nav-img">我</a>
                    <dl class="layui-nav-child">
                        <dd><a href="/user/manage">订单信息</a></dd>
                        <dd><a href="/user/info">用户信息</a>
                        <dd><a href="/password">修改密码</a></dd>
                        <dd><a href="/loginout">退了</a></dd>
                    </dl>
                </li>
            {% else %}

                <li class="layui-nav-item">
                    <a href="">注册/登录</a>
                    <dl class="layui-nav-child">
                        <dd><a href="http://localhost:5000/register">注册</a></dd>
                        <dd><a href="http://localhost:5000/login">登录</a></dd>
                    </dl>
                </li>
            {% endif %}
            <li class="layui-nav-item">
                <a href="/user/car">购物车</a>
            </li>
            <li class="layui-nav-item">
                <a href="/chat">客服<span class="layui-badge-dot"></span></a>
            </li>

        </ul>

    </div>
</div>

<div class="layui-row  layui-bg-cyan" style="padding: 8px">
    <div class="layui-col-md1" style="left: 20px">
        <button type="button" class="layui-btn layui-btn-xs" >
            <a href="/show/shop?type=0">全部</a>
        </button>
    </div>
    <div class="layui-col-md11" style="right: 20px">
          <span class="layui-breadcrumb" lay-separator="|">
            <a href="/show/shop?type=1">酒水饮料</a>
            <a href="/show/shop?type=2">当季水果</a>
            <a href="/show/shop?type=3">面包糕点</a>
            <a href="/show/shop?type=4">肉干卤味</a>
            <a href="/show/shop?type=5">糖果果冻</a>
            <a href="/show/shop?type=6">膨化食品</a>
            <a href="/show/shop?type=7">饼干曲奇</a>
            <a href="/show/shop?type=8">坚果炒货</a>
            <a href="/show/shop?type=9">蛋糕甜品</a>
            <a href="/show/shop?type=10">蛋挞披萨</a>
         </span>

    </div>
</div>


<div class="layui-row">
    <div class="layui-col-md2">
         <ul class="layui-nav layui-nav-tree layui-bg-cyan" lay-filter="test" style="top: 1px; height: 600px">
            <li class="layui-nav-item" style="top: 100px"><a href="/user/info">用户信息</a></li>
            <li class="layui-nav-item" style="top: 100px"><a href="/user/manage">订单信息</a></li>
            <li class="layui-nav-item" style="top: 100px"><a href="/get/preferences">喜好分析</a></li>
            <li class="layui-nav-item" style="top: 100px"><a href="/chat">人工服务</a></li>
        </ul>
    </div>
    <div class="layui-col-md10 layui-bg-gray" style="right: 40px">
        <div class="layuimini-container">
            <div class="layuimini-main">
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                    <legend>用户信息展示</legend>
                </fieldset>

                <form class="layui-form" action="" lay-filter="userForm">
                    <div class="layui-form-item">
                        <label class="layui-form-label">姓名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">性别</label>
                        <div class="layui-input-inline">
                            <input type="radio" name="sex" value="男" title="男" checked="">
                            <input type="radio" name="sex" value="女" title="女">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">地址</label>
                        <div class="layui-input-inline">
                            <input type="text" name="address" placeholder="请输入地址" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">邮箱</label>
                        <div class="layui-input-inline">
                            <input type="text" name="email" lay-verify="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">电话</label>
                        <div class="layui-input-inline">
                            <input type="tel" name="phone" lay-verify="required|phone" placeholder="请输入电话" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">生日</label>
                        <div class="layui-input-inline">
                            <input type="text" name="birthdate" id="birthdate" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <!-- Remove submit button since this is just for displaying -->
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" id="editUserBtn">编辑用户信息</button>
                    <button class="layui-btn" lay-submit="" lay-filter="submitUserForm" id="submitUserBtn" disabled>提交</button>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</body>
<script>
    $("#searchBtn").click(function() {
        var keyword = $("#search").val();
        window.location.href = "/show/search?"+"keyword="+keyword;
    });
</script>
<script>
    layui.use('carousel', function(){
        var carousel = layui.carousel;
        //建造实例
        carousel.render({
            elem: '#test1'
            ,width: '100%' //设置容器宽度
            ,arrow: 'always' //始终显示箭头
            //,anim: 'updown' //切换动画方式
        });
    });
</script>
<script>
    layui.use(['form', 'laydate'], function () {
        var form = layui.form
            , laydate = layui.laydate;

        laydate.render({
            elem: '#birthdate'
        });

        $.ajax({
            url: "/api/user",
            type: "GET",
            success: function(response) {
                form.val('userForm', response);

                // Disable form elements initially
                $('input[name="name"], input[name="sex"], input[name="address"], input[name="email"], input[name="phone"], input[name="birthdate"]').attr('disabled', true);

                // Enable submit button when user data is loaded
                $('#submitUserBtn').removeAttr('disabled');
            },
            error: function(error) {
                alert("没有得到数据");
            }
        });

        $("#editUserBtn").click(function() {
            $('input[name="name"], input[name="sex"], input[name="address"], input[name="email"], input[name="phone"], input[name="birthdate"]').attr('disabled', false);
        });
        form.on('submit(submitUserForm)', function (data) {
             var formData = {
                name: $("input[name='name']").val(),
                sex: $("input[name='sex']:checked").val(),
                address: $("input[name='address']").val(),
                email: $("input[name='email']").val(),
                phone: $("input[name='phone']").val(),
                birthdate: $("input[name='birthdate']").val()
            };
            console.log(formData);
            $.ajax({
                url: "/update/userinfo",
                type: "POST",
                data: formData,
                success: function(response) {
                    alert("更新成功！");
                },
                error: function(error) {
                    alert("在提交的时候出现了错误！");
                }
            });
            return false;
        });

    });
</script>
<body>
</html>